package cn.fl.customer.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.customer.service.ICstUsrRService;
import cn.fl.customer.transform.CstUsrRVOTransform;
import cn.fl.customer.vo.CstUsrRVO;
import cn.fl.framework.base.utils.WebBaseUtils;
import fl.customer.facade.customer.api.ICstUsrRApiService;
import fl.customer.facade.customer.condition.CstUsrRQueryCondition;
import fl.customer.facade.customer.dto.CstUsrRDTO;

/**
 * @Description: 客户-用户关系表（记录客户信息维护的用户） 客户端服务层接口实现
 * @Description: 持久层方法名称前缀：新增：insert* 删除：delete* 修改：update* 批量：batch* 查询对象：select* get* find* 查询集合：select*
 */
@Service
public class CstUsrRServiceImpl implements ICstUsrRService {

	/**
	 * 日志
	 */
	@SuppressWarnings("unused")
	private static final Logger logger = LoggerFactory.getLogger(ICstUsrRService.class);
	
	/**
	 * TODO 自定义 API 暴露服务
	 */
	@Autowired
	private ICstUsrRApiService cstUsrRApiService;

	@Override
	public CstUsrRVO selectById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id))return null;
		//TODO 业务逻辑
		CstUsrRDTO dto = null;//this.自定义ApiService.selectById(id);
		return CstUsrRVOTransform.toVO(dto);
	}

	@Override
	public Long add(CstUsrRVO entity) throws BaseException{
		if(null == entity)return null;
		String buOrgCd = WebBaseUtils.getBuOrgCd(entity.getOrgCd());
		entity.setBuOrgCd(buOrgCd);
		return this.cstUsrRApiService.addCstUsrR(CstUsrRVOTransform.toDTO(entity));
	}

	@Override
	public boolean removeById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id))return false;
		//return this.cstUsrRApiService.removeById(id);
		//TODO 业务逻辑
		return false;
	}
	
	/**
     * 删除
     * @param ids
     * @return
     */
    public boolean removeByIds(List<Long> ids)throws BaseException{
    	if(CollectionUtils.isEmpty(ids)){
			return false;
		};
		return false;
    }

	@Override
	public boolean modify(CstUsrRVO entity) throws BaseException{
		if(null == entity)return false;
		String buOrgCd = WebBaseUtils.getBuOrgCd(entity.getOrgCd());
		entity.setBuOrgCd(buOrgCd);
		return this.cstUsrRApiService.modifyCstUsrR(CstUsrRVOTransform.toDTO(entity));
	}

	@Override
	public Pager searchListPage(Pager page) throws BaseException{
		//if(null == page)page = new Pager();
		//return this.cstUsrRApiService.searchListPage(page);
		//TODO 业务逻辑
		return null;
	}

	@Override
	public List<CstUsrRVO> searchList(CstUsrRQueryCondition curCondition)
			throws BaseException {
		List<CstUsrRDTO> list = this.cstUsrRApiService.searchCstUsrRList(curCondition);
		return CstUsrRVOTransform.toVOList(list);
	}
}
